home *** CD-ROM | disk | FTP | other *** search
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
- /* */
- /* Prototype HP15C Calculator */
- /* James C. Ullrey */
- /* INRESCO */
- /* © 1990 */
- /* Version 13.97a */
- /* */
- /* UPDATE SEGMENT */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
-
-
- /*****************************************************************/
- /* I N C L U D E S
- /*****************************************************************/
-
- #ifndef __C14__
- #include "PredatorPrey.h"
- #endif
- #include "calc_update.h"
- #include "calc_controls.h"
- #include "calc_inits.h"
- #include "calc_draw_object.h"
- #include <Quickdraw.h>
-
- //#define gray 0xFFFFFFE8
- //#define ltGray 0xFFFFFFE0
- //#define black 0xFFFFFFF0
-
- /********************************************************************
- /* G L O B A L V A R I A B L E D E C L A R A T I O N S
- /********************************************************************/
-
- extern Boolean Transmogrified;
- extern long gState;
- extern long gsState;
- extern long sto;
- extern long rcl;
- extern long wait;
- extern long gFlag;
- extern long fFlag;
- extern long sWait;
- extern long rWait;
- extern long lblWait;
- extern long plus;
- extern long minus;
- extern long timesF;
- extern long divide;
- extern long gDot;
- extern long gDigits;
- extern long gtoWait;
- extern Rect gArrow_box;
- extern Rect gCircle_box;
- extern Rect gSquare_box;
- extern Rect gCube_box;
- extern Rect gHouse_box;
- extern Rect gBackGrnd_box;
- extern Rect gPalette_frame;
- extern WindowPtr lastPtr;
- extern Rect gFirstCalcIcon,gSecondCalcIcon,gThirdCalcIcon;
- extern Rect gFourthCalcIcon,gFifthCalcIcon,gSixthCalcIcon;
-
- /*****************************************************************/
- /* P R O T O T Y P E S
- /*****************************************************************/
-
-
-
- void size_scrollbars (WindowPtr wPtr);
-
-
- /*****************************************************************/
- /*****************************************************************/
- /*
- /* R O U T I N E S
- /*
- /*****************************************************************/
- /*****************************************************************/
-
-
- void update_seg() {} /* for reference in "UnloadSeg()" calls */
-
-
-
-
- /********************** DrawMyPicture ************************/
- void DrawCalcPicture( PicHandle thePicture, WindowPtr pictureWindow )
- {
- Rect myRect;
-
- myRect = pictureWindow->portRect;
- DrawPicture( thePicture, &myRect );
- }
-
- /*********************** DrawIconize *************************/
- void DrawIconize( PicHandle thePicture, WindowPtr pictureWindow )
- {
- Rect myRect;
-
- myRect = pictureWindow->portRect;
- DrawPicture( thePicture, &myRect );
- }
-
- /********************** LocateWindow *************************/
- void LocateWindow( WindowPtr wptr )
- /* Calculates left, top position of center & moves window */
- {
- short scrW, scrV;
- short mBH;
- Rect scrRect;
- Point where;
-
- WinRect( wptr, &scrRect ); // Returns the window global coordinates in scrRect
- scrW = qd.screenBits.bounds.right - qd.screenBits.bounds.left; // Calculates screen width
- mBH = GetMBarHeight();
- scrV = ( qd.screenBits.bounds.bottom - qd.screenBits.bounds.top ) - mBH; // Calculates screen height
- where.v = ( scrV - ( scrRect.bottom - scrRect.top ) ) + mBH;
- /* where.v = ( scrV - ( scrRect.bottom - scrRect.top ) )/2; // Calculates top left vert coordinate*/
- where.h = qd.screenBits.bounds.left;
- /* where.h = ( scrW - ( scrRect.right - scrRect.left ) )/2; // Calculates the top left horiz coordinate*/
- MoveWindow( wptr, where.h, where.v, false ); // Moves window to new location
- }
-
- /************************* WinRect ***************************/
- Rect *WinRect( WindowPtr wPtr, Rect *gRect )
- /* Returns window portRect in global coordinates*/
- {
- GrafPtr savePort;
-
- GetPort( &savePort );
- SetPort( wPtr );
- *gRect = wPtr->portRect;
- LocalToGlobal( & ( topLeft( *gRect ) ) ); // Converts local coordinates to global coordinates
- LocalToGlobal( & ( botRight( *gRect ) ) );
- SetPort( savePort );
- return ( gRect ); // Returns the global coordinates of the window in gRect
- }
-
-
-
- /************************ DoKiller ***************************/
- void DoKiller()
- {
- long dummy;
-
- EraseRect( &gSkullRect30 );
- DrawPicture( gSkullPicture30, &gSkullRect30 );
- EraseRect( &gSkullRect35 );
- DrawPicture( gSkullPicture35, &gSkullRect35 );
- EraseRect( &gSkullRect40 );
- DrawPicture( gSkullPicture40, &gSkullRect40 );
- EraseRect( &gSkullRect45 );
- DrawPicture( gSkullPicture45, &gSkullRect45 );
- EraseRect( &gSkullRect50 );
- DrawPicture( gSkullPicture50, &gSkullRect50 );
- EraseRect( &gSkullRect55 );
- DrawPicture( gSkullPicture55, &gSkullRect55 );
- EraseRect( &gSkullRect60 );
- DrawPicture( gSkullPicture60, &gSkullRect60 );
- EraseRect( &gSkullRect65 );
- DrawPicture( gSkullPicture65, &gSkullRect65 );
- EraseRect( &gSkullRect70 );
- DrawPicture( gSkullPicture70, &gSkullRect70 );
- EraseRect( &gSkullRect75 );
- DrawPicture( gSkullPicture75, &gSkullRect75 );
- EraseRect( &gSkullRect80 );
- DrawPicture( gSkullPicture80, &gSkullRect80 );
- EraseRect( &gSkullRect85 );
- DrawPicture( gSkullPicture85, &gSkullRect85 );
- EraseRect( &gSkullRect90 );
- DrawPicture( gSkullPicture90, &gSkullRect90 );
- EraseRect( &gSkullRect95 );
- DrawPicture( gSkullPicture95, &gSkullRect95 );
- EraseRect( &gSkullRect100 );
- DrawPicture( gSkullPicture100, &gSkullRect100 );
- Delay(140L,&dummy);
- EraseRect( &gSkullRect100 );
- InvalRect( &gSkullRect100 );
-
- }
-
- /********************* MaintainColor *************************/
- Boolean MaintainColor(void)
- {
- long pointResult;
- short theLowResult,theHighResult;
- Point theNoColorPt;
- Point theTmNoColorPt;
- Boolean result;
-
- result = TRUE;
- if(!Transmogrified)
- {
- pointResult = PinRect(&gGfxnRect,theNoColorPoint);
- theHighResult = (pointResult >> 16) & 0xFFFF;
- theLowResult = pointResult & 0xFFFF;
- SetPt(&theNoColorPt,theLowResult,theHighResult);
- LocalToGlobal(&theNoColorPt);
- if(theNoColorPt.h > gNoColorDragRect.right)
- result = FALSE;
- }
- else
- {
- pointResult = PinRect(&gNGfxnRect,theTmNoColorPoint);
- theHighResult = (pointResult >> 16) & 0xFFFF;
- theLowResult = pointResult & 0xFFFF;
- SetPt(&theTmNoColorPt,theLowResult,theHighResult);
- LocalToGlobal(&theTmNoColorPt);
- if(theTmNoColorPt.h > gNoColorDragRect.right)
- result = FALSE;
- }
- return(result);
- }
-
-
- /*********************** do_update ***************************/
- void do_update(WindowPtr wPtr)
- {
- short i,index;
- short obj_type;
- short x, y, print_page_width, print_page_height;
- Point offset;
- Rect obj_rect, doc_rect, window_rect;
- WindowPtr save_port;
- RgnHandle save_clip, vis_rgn;
- PenState pen_state;
- WObjsHandle w_objs_hndl;
- WPObjsHandle wp_objs_hndl;
- RgnHandle doc_rgn, gray_rgn;
- THPrint pr_info_hndl;
- Boolean spec;
- short the_object;
-
- spec = FALSE;
-
-
- /************* Save the initial state of the machine **********/
-
-
- GetPort(&save_port);
- SetPort(wPtr); /* make update window active grafPort */
-
- if(wPtr == gProgWindow)
- {
- wp_objs_hndl = (WPObjsHandle)GetWRefCon(wPtr);
- offset = (**wp_objs_hndl).scrollAmount;
-
- BeginUpdate(wPtr); /* visRgn temporarily = updateRgn */
-
-
- if(progList) LUpdate( gProgWindow->visRgn,progList );
- EndUpdate(wPtr); /* restore normal visRgn of grafport */
- }
- else
- {
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
- offset = (**w_objs_hndl).scrollAmount;
-
- BeginUpdate(wPtr); /* visRgn temporarily = updateRgn */
-
- save_clip = NewRgn();
- GetClip(save_clip);
-
- GetPenState(&pen_state);
- PenNormal();
-
-
-
- /********* Set the clip area and erase the "entire" window **********/
-
-
- ClipRect(& wPtr->portRect);
- //#ifdef DEBUGGING
- //DebugStr("\pRight before EraseRect()");
- //#endif
- EraseRect(& wPtr->portRect); /* note: only the update area will be erased */
- //#ifdef DEBUGGING
- //DebugStr("\pRight after EraseRect()");
- //#endif
-
- /***** Draw the palette, grow icon and controls, and set up clipping ******/
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
- the_object = (**w_objs_hndl).paletteSetting;
-
-
-
- /***************** Draw the palette icons ******************/
-
- if((**w_objs_hndl).isPrey == 1)
- {
- ; /* do nothing */
- }
- else
- {
- draw_palette(wPtr);
- clip_4_palette(wPtr);
- }
-
- if((**w_objs_hndl).isPrey == 1)
- {
- ; /* do nothing */
- }
- else
- {
- DrawGrowIcon(wPtr);
-
- DrawControls(wPtr);
- }
-
-
- /************* Fill in the gray area outside the "document" **********/
-
- /**/
- /* gray_rgn = NewRgn();*/
- /* doc_rgn = NewRgn();*/
- /* */
- /* SetRect(&doc_rect, 0, 0, (**w_objs_hndl).hDocLimit, (**w_objs_hndl).vDocLimit);*/
- /* OffsetRect(&doc_rect, -offset.h, -offset.v);*/
- /* RectRgn (doc_rgn, &doc_rect);*/
- /* */
- /* window_rect = wPtr->portRect;*/
- /* window_rect.bottom -= 15;*/
- /* window_rect.right -= 15;*/
- /* RectRgn (gray_rgn, &window_rect);*/
- /* */
- /* DiffRgn(gray_rgn, doc_rgn, gray_rgn);*/
- /* */
- /* //FillRgn(gray_rgn, gray);*/
- /* //PenPat((PatPtr)gray); /* new 940418 »*/
- /* PenPat(&qd.gray); /* new 940502 »*/
- /* //FillRgn(gray_rgn, (PatPtr)gray);*/
- /* FillRgn(gray_rgn, &qd.gray);*/
- /* InsetRect(&doc_rect, -1, -1);*/
- /* FrameRect(&doc_rect);*/
- /* */
- /* DisposeRgn(gray_rgn);*/
- /* DisposeRgn(doc_rgn);*/
- /* */
-
- /************* Draw page boundaries on the document **********/
-
-
- //PenPat(qd.gray);
-
- /* pr_info_hndl = (**w_objs_hndl).prInfoHndl; /* uncommented in SimpleText »*/
- /* */
- /* print_page_width = (**pr_info_hndl).prInfo.rPage.right; /* uncommented in SimpleText »*/
- /* print_page_height = (**pr_info_hndl).prInfo.rPage.bottom; /* uncommented in SimpleText »*/
- /* */
- /* x = print_page_width;*/
- /* while (x < (**w_objs_hndl).hDocLimit)*/
- /* {*/
- /* MoveTo(x - offset.h, -offset.v);*/
- /* LineTo(x - offset.h, doc_rect.bottom - 2); /* doc_rect is already offset! »*/
- /* x += print_page_width; /* the '-2' is so not to overwrite doc border. »*/
- /* }*/
- /* */
- /* y = print_page_height;*/
- /* while (y < (**w_objs_hndl).vDocLimit)*/
- /* {*/
- /* MoveTo(-offset.h, y - offset.v);*/
- /* LineTo(doc_rect.right - 2, y - offset.v);*/
- /* y += print_page_height;*/
- /* }*/
-
- PenNormal();
-
-
-
- /************* Draw the objects in the window **********/
-
- /**
- Go through the entire list of objects in the window. Draw objects that are
- of a type other than "NO_OBJ" and which are located at least partly in the
- update region. Update performance is improved by drawing only objects that
- are located in the update region.
-
- (Remember that during update, the window "visRgn" is set to the update
- region).
- **/
- vis_rgn = NewRgn();
- vis_rgn = wPtr->visRgn;
-
- if((**w_objs_hndl).hasBackGround)
- {
- index = MAX_OBJECTS + 2;
- draw_object(wPtr,index, spec); /* this */
- }
- for(index = 0; index < MAX_OBJECTS; index++) /* MAX_OBJECTS = 30 */
- if((**w_objs_hndl).object[index].type != NO_OBJ) /* NO_OBJ = 0 */
- {
- obj_rect = (**w_objs_hndl).object[index].bounds;
- OffsetRect(&obj_rect, -offset.h, -offset.v);
- if(RectInRgn(&obj_rect, vis_rgn))
- {
- draw_object(wPtr,index, spec);
- }
- }
-
- EndUpdate(wPtr); /* restore normal visRgn of grafport */
-
-
-
-
- /************* Restore the state of the machine **********/
-
-
- SetPenState(&pen_state);
-
- SetClip(save_clip);
- DisposeRgn(save_clip);
- }
- SetPort(save_port);
-
- } /* end of do_update) */
-
- void do_grow (WindowPtr wPtr,Point global_pt)
- {
- short v_size, h_size;
- long new_size;
- Rect size_rect, grow_box;
-
-
-
- /****** Set up the range of allowable window size and track the mouse **********/
-
-
- SetRect(&size_rect, H_MIN_SIZE,
- V_MIN_SIZE,
- qd.screenBits.bounds.right,
- qd.screenBits.bounds.bottom);
-
- new_size = GrowWindow (wPtr, global_pt, &size_rect);
- v_size = HiWord(new_size);
- h_size = LoWord(new_size);
-
-
-
- /*********************** Re-size the Window ********************/
-
-
- SetRect(&grow_box, wPtr->portRect.right - 15,
- wPtr->portRect.bottom - 15,
- wPtr->portRect.right,
- wPtr->portRect.bottom);
- InvalRect(&grow_box);
-
- SizeWindow(wPtr, h_size, v_size, TRUE);
-
- SetRect(&grow_box, wPtr->portRect.right - 15,
- wPtr->portRect.bottom - 15,
- wPtr->portRect.right,
- wPtr->portRect.bottom);
- InvalRect(&grow_box);
-
- /*********** Resize scrollbars and do scrolling if necessary ***********/
-
- size_scrollbars(wPtr);
-
- return;
-
- } /* end of do_grow() */
-
-
- void size_scrollbars(WindowPtr wPtr)
- {
- short h, v, max_scroll;
- Rect cntl_rect, w_rect;
- WObjsHandle w_objs_hndl;
- ControlHandle h_scroll_hndl, v_scroll_hndl;
- ControlHandle cntl_hndl;
-
-
- w_objs_hndl = (WObjs**)GetWRefCon(wPtr);
- v_scroll_hndl = (**w_objs_hndl).myVCntrlHdl;
- h_scroll_hndl = (**w_objs_hndl).myHCntrlHdl;
-
-
-
- /************* Set size & position the scrollbars to new window size **********/
-
-
-
- w_rect = wPtr->portRect;
-
- HideControl(v_scroll_hndl);
-
- h = w_rect.right - 15;
- v = w_rect.top - 1;
- MoveControl (v_scroll_hndl, h, v);
-
- v = (w_rect.bottom -13) - w_rect.top;
- SizeControl(v_scroll_hndl, 16, v);
-
- ShowControl(v_scroll_hndl);
-
- cntl_rect = (**v_scroll_hndl).contrlRect;
- ValidRect(&cntl_rect);
-
-
- HideControl(h_scroll_hndl);
-
- h = w_rect.left - 1;
- v = w_rect.bottom - 15;
- MoveControl(h_scroll_hndl, h, v);
-
- h = (w_rect.right - 13) - w_rect.left;
- SizeControl(h_scroll_hndl, h, 16);
-
- ShowControl(h_scroll_hndl);
-
- cntl_rect = (**h_scroll_hndl).contrlRect;
- ValidRect(&cntl_rect);
-
-
-
- /****** Calculate and set the max-scroll values for the new size *******/
-
-
- max_scroll = (**w_objs_hndl).vDocLimit - (w_rect.bottom - w_rect.top - 15);
- if(max_scroll < 0) max_scroll = 0;
- SetCtlMax(v_scroll_hndl, max_scroll);
-
- max_scroll = (**w_objs_hndl).hDocLimit - (w_rect.right - w_rect.left - 15);
- if(max_scroll < 0) max_scroll = 0;
- SetCtlMax(h_scroll_hndl, max_scroll);
-
-
-
- /****** Does image need to scroll to keep it positioned properly? *******/
-
-
- do_scroll(wPtr,cntl_hndl);
-
- return;
-
- } /* end of size_scrollbars() */
-
-
- /********************* draw_palette **************************/
- void draw_palette(WindowPtr wPtr)
- {
- short the_object;
- PenState save_pen;
- RgnHandle save_clip;
- Rect temp_rect;
- Handle icon_hndl;
- WObjsHandle w_objs_hndl;
-
-
-
- /*********************** Save intial GrafPort conditions **********************/
-
-
- SetPort(wPtr);
-
- save_clip = NewRgn();
- GetClip(save_clip);
-
- GetPenState(&save_pen);
- PenNormal();
-
-
- /***************** Set window clip area to exclude scrollbars ******************/
-
-
- temp_rect = wPtr->portRect;
- temp_rect.right -= 15;
- temp_rect.bottom -= 15;
-
- ClipRect(&temp_rect);
-
- w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
- the_object = (**w_objs_hndl).paletteSetting;
-
-
-
- /***************** Draw the palette icons ******************/
-
- if(the_object == PLOT_OBJ)
- {
- ; /* do nothing */
- }
- else
- {
- EraseRect(&gPalette_frame);
-
- icon_hndl = GetResource('ICON', ARROW_ID);
- PlotIcon(&gArrow_box, icon_hndl);
-
- if((**w_objs_hndl).isArmed == TRUE)
- {
- switch((**w_objs_hndl).armament_type)
- {
- case 0:
- switch((**w_objs_hndl).arms_selected)
- {
- case 0:
- icon_hndl = GetResource('ICON', GUNS_ID);
- PlotIcon(&gCircle_box, icon_hndl);
- break;
- }
- break;
- case 1:
- switch((**w_objs_hndl).arms_selected)
- {
- case 0:
- icon_hndl = GetResource('ICON', GUNS_ID);
- PlotIcon(&gCircle_box, icon_hndl);
- break;
- case 1:
- icon_hndl = GetResource('ICON', MISSLES_ID);
- PlotIcon(&gCircle_box, icon_hndl);
- break;
- }
- break;
- case 2:
- switch((**w_objs_hndl).arms_selected)
- {
- case 0:
- icon_hndl = GetResource('ICON', GUNS_ID);
- PlotIcon(&gCircle_box, icon_hndl);
- break;
- case 1:
- icon_hndl = GetResource('ICON', MISSLES_ID);
- PlotIcon(&gCircle_box, icon_hndl);
- break;
- case 2:
- icon_hndl = GetResource('ICON', N_BOMB_ID);
- PlotIcon(&gCircle_box, icon_hndl);
- break;
- }
- break;
- }
- }
- else
- {
- icon_hndl = GetResource('ICON', CIRCLE_ID);
- PlotIcon(&gCircle_box, icon_hndl);
- }
-
- if((**w_objs_hndl).hasBackGround)
- {
- switch((**w_objs_hndl).targets_left)
- {
- case 0:
- icon_hndl = GetResource('ICON', ZERO_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- break;
- case 1:
- icon_hndl = GetResource('ICON', ONE_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- break;
- case 2:
- icon_hndl = GetResource('ICON', TWO_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- break;
- case 3:
- icon_hndl = GetResource('ICON', THREE_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- break;
- case 4:
- icon_hndl = GetResource('ICON', FOUR_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- break;
- case 5:
- icon_hndl = GetResource('ICON', FIVE_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- break;
- case 6:
- icon_hndl = GetResource('ICON', SIX_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- break;
- }
- }
- else
- {
- icon_hndl = GetResource('ICON', SQUARE_ID);
- PlotIcon(&gSquare_box, icon_hndl);
- }
-
- icon_hndl = GetResource('ICON', CUBE_ID);
- PlotIcon(&gCube_box, icon_hndl);
-
- icon_hndl = GetResource('ICON', HOUSE_ID);
- PlotIcon(&gHouse_box, icon_hndl);
-
- icon_hndl = GetResource('ICON', BACKGRND_ID);
- PlotIcon(&gBackGrnd_box, icon_hndl);
- }
-
- /********* Put light gray background into selected tool if window is active ******/
-
-
- PenMode(patOr);
- //PenPat((PatPtr)ltGray);
- PenPat(&qd.ltGray);
-
- if(wPtr == FrontWindow())
- {
- if(the_object == ARROW_OBJ) PaintRect(&gArrow_box); /* ARROW_OBJ = 1 */
-
- if(the_object == CIRCLE_OBJ) PaintRect(&gCircle_box); /* CIRCLE_OBJ = 2 */
-
- if(the_object == SQUARE_OBJ) PaintRect(&gSquare_box); /* SQUARE_OBJ = 3 */
-
- if(the_object == CUBE_OBJ) PaintRect(&gCube_box); /* CUBE_OBJ = 4 */
-
- if(the_object == HOUSE_OBJ) PaintRect(&gHouse_box); /* HOUSE_OBJ = 5 */
-
- if(the_object == BACKGRND_OBJ) PaintRect(&gBackGrnd_box); /* BACKGRND_OBJ = 7 */
- }
-
-
-
- /***************** Restore initial GrafPort conditions ******************/
-
-
- SetPenState(&save_pen);
-
- SetClip(save_clip);
- DisposeRgn(save_clip);
-
- } /* end of draw_palette() */
-
-
-
-
-